from django.db import models

# Create your models here.


# 部门表1
class DepartmentModel(models.Model):
    dname = models.CharField(max_length=100,default='',verbose_name='部门名称')

    class Meta:
        db_table = 'tb_department'
    def __str__(self):
        return self.dname

# 职级表2
class RankModel(models.Model):
    rname = models.CharField(max_length=100,default='',verbose_name='职级名称')

    class Meta:
        db_table = 'tb_rank'
    def __str__(self):
        return self.rname


# 岗位表3
class PostsModel(models.Model):
    pname = models.CharField(max_length=100,default='',verbose_name='岗位名称')

    class Meta:
        db_table = 'tb_posts'
    def __str__(self):
        return self.pname


# 权限表4
class JurisdictionModel(models.Model):
    jname = models.CharField(max_length=100,default='',verbose_name='权限名称')
    pathname = models.CharField(max_length=100,default='',verbose_name='路由')

    class Meta:
        db_table = 'tb_jurisdiction'
    def __str__(self):
        return self.jname


# 角色表5
class RoleModel(models.Model):
    roname = models.CharField(max_length=100,default='',verbose_name='角色名称')
    juris = models.ForeignKey(JurisdictionModel,on_delete=models.CASCADE,verbose_name='拥有权限')

    class Meta:
        db_table = 'tb_role'
    def __str__(self):
        return self.roname


# 用户表6
class UserModel(models.Model):
    username = models.CharField(max_length=100,default='',verbose_name='用户名')
    zhanghao = models.CharField(max_length=100,default='',verbose_name='账号')
    password = models.CharField(max_length=100,default='',verbose_name='密码')
    mobile = models.CharField(max_length=100,default='',verbose_name='手机号')
    mail = models.CharField(max_length=100,default='',verbose_name='邮箱')
    department = models.ForeignKey(DepartmentModel,on_delete=models.CASCADE,verbose_name='所属部门')
    rank = models.ForeignKey(RankModel,on_delete=models.CASCADE,verbose_name='所属职级')
    role = models.ForeignKey(RoleModel,on_delete=models.CASCADE, verbose_name='所属角色')
    post = models.ForeignKey(PostsModel,on_delete=models.CASCADE, verbose_name='所属岗位')
    state = models.CharField(max_length=100,default='',verbose_name='员工状态')     # 1  离职 2 出差 3 请假

    class Meta:
        db_table = 'tb_user'
    def __str__(self):
        return self.username
